package next.ControllerResponsibilities;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;
import next.control.support.GenericTreeNode;

public class C_Navigation {
	
	//--Variables 
    private GenericTreeNode<String> SeraTree, ActualNode;
    private ArrayList< GenericTreeNode<String> > Path= new ArrayList<  GenericTreeNode<String> >(50);
    //private static String Navigation_WHO=null;
    private static String Navigation_WHERE=null;
	
   	public C_Navigation() {
		super();
		SeraTree=new GenericTreeNode<String>("next.CommonProfile.Dashboard_Principal");
		
		//--we create the GUI Hierarchy
		List < GenericTreeNode<String> > child=SeraTree.getChildren();
		child.add(new GenericTreeNode<String>("next.CommonProfile.Dashboard_SI"));
		child.add(new GenericTreeNode<String>("next.CommonProfile.Dashboard_SU"));
		child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
		SeraTree.setChildren(child);
		
		  for (GenericTreeNode<String> node : SeraTree.getChildren()) {
			  createChild (node);
	        }
		  
		  ActualNode=new GenericTreeNode<String>(SeraTree);
	}
   	
   		
     /**Helper Function to create GUI Hierarchy*/
		public void createChild (GenericTreeNode<String> daddy)
	{
			List < GenericTreeNode<String> > child= daddy.getChildren();
		
		if (daddy.getData().equalsIgnoreCase("next.CommonProfile.Dashboard_SI")){
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
			child.add(new GenericTreeNode<String>("next.Admin.Admin_Principal"));
			child.add(new GenericTreeNode<String>("next.Client.Client_Principal"));	
			child.add(new GenericTreeNode<String>("next.Member.Member_Principal"));	
		}
		else if (daddy.getData().equalsIgnoreCase("next.CommonProfile.Dashboard_SU")){
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
			//child.add(new GenericTreeNode<String>("next.CommonProfile.DashboardPrincipal"));	
		}
		else if (daddy.getData().equalsIgnoreCase("next.Admin.Admin_Principal")){
			child.add(new GenericTreeNode<String>("next.CommonProfile.PersonalInfo"));
			child.add(new GenericTreeNode<String>("next.CommonProfile.Products"));
			child.add(new GenericTreeNode<String>("next.Admin.Business_Rules"));
			child.add(new GenericTreeNode<String>("next.view.support.CustomList"));
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
		}
		else if (daddy.getData().equalsIgnoreCase("next.view.support.CustomList")){
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.MapsFunctionality"));
			
		}else if (daddy.getData().equalsIgnoreCase("next.SupportFunctionality.MapsFunctionality")){
			child.add(new GenericTreeNode<String>("next.SupportFunctionality.VoiceRecogFunctionality"));
			
			
		}

		daddy.setChildren(child);
		 for (GenericTreeNode<String> node : daddy.getChildren()) {
			  createChild (node);
	        }
	}

		/**Determines if is possible to go to Navigation_WHERE from Navigation_WHO*/	
	public boolean GO ()
	{
		
		  for (GenericTreeNode<String> node : ActualNode.getChildren()) {
			 if (node.getData().equalsIgnoreCase(Navigation_WHERE)){
				 Path.add(new GenericTreeNode<String>(ActualNode));
				 ActualNode=new GenericTreeNode<String>(node);
			    return true;
			 }
	      }
		  return false;
	}
	
	/**An activity was closed, so its time to comeback to the last father node*/	
	public void CLOSE ()
	{
		if (Path.size()!=0){
		ActualNode=Path.get(Path.size()-1);
		Path.remove(Path.size()-1);
		}
	}

	public static String getNavigation_WHERE() {
		return Navigation_WHERE;
	}

	public static void setNavigation_WHERE(String navigation_WHERE) {
		Navigation_WHERE = navigation_WHERE;
	}


	public boolean PROFILE() {
					
		if( (ActualNode.getData().equalsIgnoreCase("next.Admin.Admin_Principal") || 
					ActualNode.getData().equalsIgnoreCase("next.Client.Client_Principal") ||	
					ActualNode.getData().equalsIgnoreCase("next.Member.Member_Principal")) )
			{
			return true;
			}
		else {
			Log.d("EVENT", ActualNode.getData());
			return false; 
			}
	}

}
